﻿//------------------------------------------------------------
// Game Framework
// Copyright © 2013-2020 Jiang Yin. All rights reserved.
// Homepage: https://gameframework.cn/
// Feedback: mailto:ellan@gameframework.cn
//------------------------------------------------------------

using System;

namespace StarForce
{
    public static class WebUtility
    {
        public static string EscapeString(string stringToEscape)
        {
            return Uri.EscapeDataString(stringToEscape);
        }

        public static string UnescapeString(string stringToUnescape)
        {
            return Uri.UnescapeDataString(stringToUnescape);
        }
        
        /// <summary>
        /// 利用算法 根据名字计算唯一值
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public static int GetIntHash(string id)
        {
            int hash = 0;
            if (id.Length == 0)
            {
                return hash;
            }

            for (int i = 0; i < id.Length; i++)
            {
                char c = id[i];
                hash = ((hash << 5) - hash) + c;
                hash = hash & hash; // Convert to 32bit integer
            }

            return hash;
        }
        
        public static string GetRegularPath(string path)
        {
            return path?.Replace('\\', '/');
        }
    }
}
